package com.zym.testpoi.controller;

import com.zym.testpoi.pojo.Class;
import com.zym.testpoi.pojo.User;
import com.zym.testpoi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/download")
    public void download(HttpServletResponse response) throws IOException {
        List<User> sheet1 = new ArrayList<>();
        sheet1.add(new User("zhangsan",23,"football"));
        sheet1.add(new User("lisi",24,"song"));
        sheet1.add(new User("wangwu",25,"computergame"));

        List<Class> sheet2 = new ArrayList<>();
        sheet2.add(new Class(1,"班级1"));
        sheet2.add(new Class(2,"班级2"));

        List<Object> dataList = new LinkedList<>();

        List<String> sheetNameList = new LinkedList<>();
        sheetNameList.add("第一个sheet页");
        sheetNameList.add("第二个sheet页");

        dataList.add(sheet1);
        dataList.add(sheet2);

        userService.download(dataList,sheetNameList,response);
    }
}
